package logic

import (
	"box-fresh-serv/box_fresh_servrpc/box_fresh_servrpc"
	"box-fresh-serv/box_fresh_servrpc/internal/svc"
	"box-fresh-serv/modles/mysql"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAddLogic) GoodsAdd(in *box_fresh_servrpc.GoodsAddRequest) (*box_fresh_servrpc.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line

	var goods = mysql.Goods{
		Title: in.Title,
		Price: float64(in.Price),
		Stock: in.Stock,
		Image: in.Image,
	}

	err := goods.GoodsAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &box_fresh_servrpc.GoodsAddResponse{
		GoodsId: int64(goods.ID),
	}, nil
}
